package com.xnx3.liuyuanshuai;

import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Student student =new Student("张三",21,202221189);
        System.out.println("原始对象："+ student);

        try (ObjectOutputStream oos =new ObjectOutputStream(Files.newOutputStream(Paths.get("student.obj")))){
            oos.writeObject(student);
            System.out.println("对象已序列化并写入文件。");
        } catch (IOException e) {
            e.printStackTrace();
        }
        try (ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(Paths.get("student.obj")))){
            Student deserializedStudent =(Student) ois.readObject();
            System.out.println("反序列对象："+deserializedStudent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
